#include "sort.h"
int partition(int *array, int len)
{
	int pivot = array[0];
	int high = len - 1;
	int low = 0;

	if(len < 2){
		return 0;
	}
	
	while(low!=high){
		while(low<high){
			if(array[high] < pivot){
				array[low] = array[high];
				break;
			}
			high --;
		}
		while(low<high){
			if(array[low] > pivot){
				array[high] = array[low];
				break;
			}
			low ++;
		}
	}
	//low == high
	array[low] = pivot;
	return low;
}

int quick_sort(int *array, int len)
{
	if(len < 2){
		return 0;
	}
	int pos = partition(array, len);
	quick_sort(array, pos);
	quick_sort(array+pos+1, len-pos-1);
	return 0;
}

